package yogiro.dao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.springframework.orm.ibatis.SqlMapClientTemplate;

import yogiro.to.CommentTO;

public class CommentDAO {
private SqlMapClientTemplate sqlMap;
	
	public CommentDAO(SqlMapClientTemplate sqlMap){
		this.sqlMap = sqlMap;
	}
	
	public int sequence() throws SQLException{
		return (int)sqlMap.queryForObject("sequence");
	}
	//전체조회
	public ArrayList<CommentTO> selectAllComment(int tourNo)throws SQLException{
		return (ArrayList<CommentTO>)sqlMap.queryForList("selectAllComment",tourNo);
		
	}
	
	//삽입 메소드
	public Object insertComment(CommentTO cto)throws SQLException{
		return sqlMap.insert("insertComment",cto);
	}
	
	//삭제 메소드
	public Object deleteComment(int commentNo,int tourNo)throws SQLException{
		HashMap map = new HashMap();
		map.put("commentNo", commentNo);
		map.put("tourNo", tourNo);
		return sqlMap.delete("deleteComment",map);
	}
	
	//no로 조회
	public CommentTO selectByNo(int commentNo)throws SQLException{
		return (CommentTO)sqlMap.queryForList("selectByNo",commentNo);
	}
	
	//no로 조회한 값 update
	public Object updateCommentReply(int refamily, int restep)throws SQLException{
		HashMap map = new HashMap();
		map.put("refamily", refamily);
		map.put("restep", restep);
		return sqlMap.update("updateCommentReply",map);
	}
}
